package com.tool_stdy.DesignTest;

/**
 * Created by yan_li on 2016/1/28.
 */
public class PersonModel {

    private int age;
    private int length;
    private int siz;
    private String name;
    private String address;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getSiz() {
        return siz;
    }

    public void setSiz(int siz) {
        this.siz = siz;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public static class PersonBuilder{
        private int age;
        private int length;
        private int siz;
        private String name;
        private String address;

        /**
         * 以下是为多个数据赋值，返回同一个对象
         * @param value
         * @return
         */
        public PersonBuilder age(int value){
            this.age=value;
            return this;
        }
        public PersonBuilder length(int vale){
            this.length=vale;
            return this;
        }
        public PersonBuilder siz(int vale){
            this.siz = vale;
            return this;
        }
        public PersonBuilder name(String value){
            this.name = value;
            return this;
        }
        public PersonBuilder address(String value){
            this.address=value;
            return this;
        }

        /**
         * 用于生成Builder对象,当然可以加上必要的参数
         */
        public PersonBuilder (){
        }

        /**
         * 用于生成我们要构建的对象
         * @return
         */
        public PersonModel build(){
            return new PersonModel(this);
        }
    }

    /**
     * 提供私有的构造方法,通过构造器来给所需要的参数赋值
     * @param builder
     */
    private PersonModel(PersonBuilder builder){
        this.name = builder.name;
        this.address =builder.address;
        this.age=builder.age;
        this.siz=builder.siz;
        this.length=builder.length;
    }
}
